package com.cai.handle;

import com.alibaba.fastjson.JSON;
import com.cai.common.result.ResultVO;
import com.cai.common.result.StatusCode;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Title: ResultException
 * @Author RuoLi
 * @Package com.cai.handle
 * @Date 2024/1/15 10:49
 * @description: 前端返回异常数据
 */
public class ResultException {
    public static void handlerException(HttpServletResponse response,StatusCode code,RuntimeException e) throws IOException {
        response.setContentType("application/json; charset=utf-8");
        ResultVO jsonResult =new ResultVO(code,e.getMessage());
        PrintWriter writer = response.getWriter();
        writer.println(JSON.toJSONString(jsonResult));
        writer.close();
    }
}
